var initbase = require('./initbase');
var layer = require('layer');
var request = require('request'); 

//通过元素绑定请求路径

return function(params){
    params = extend({
        preDeal:function(data){
            return data;
        }
    },params)
    return function(e,elem,data){
        var mainObj = this;
        e.stopPropagation();
        
        if(elem.hasClass('j-del')){//单行删除
            data = initbase.getData('',elem);
        }else{//多行勾选删除
             data = initbase.checked.call(mainObj,'',elem);
             delete data.list;
        }
        if(!data){
            return ;
        }
        //预处理请求参数
        data = params.preDeal(data);
        
        var url = params.url;
        layer({
            content:'<p style="padding-top:40px;text-align:center;"><i class="iconfont ui-warn">&#xe678;</i></p><p style="padding:8px 0 24px; text-align:center;">'+
                (typeof(params.cusMsg) ==='undefined'?'您确定删除这'+params.msg+'？':params.cusMsg)+'</p>',
            title:{
                enable:false
            },
            confirm:{
                enable:true,
                text:'确定',
                callback:function(main,index){
                    request.post(url,data,function(res){
                        initbase.submitback.call(mainObj,res);
                    },'正在删除..');
                    return true;
                }
            }
        })
    }
}